package com.sunshinew.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunshinew.dao.UserMapper;
import com.sunshinew.entity.User;
import com.sunshinew.service.UserService;
import com.sunshinew.utils.DataGridView;
import com.sunshinew.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaomingxing
 * @create 2021/4/7 12:25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService  {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User getUserByUserName(String username) {
//        User user = new User();
//        user.setUsername(username);
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(username),User::getUsername,username);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    @Override
    public DataGridView loadAllLogInfo(UserVo userVo){
        // 分页
        IPage<User> page = new Page<>(userVo.getPage(),userVo.getLimit());

        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(userVo.getRealname()),User::getRealname,userVo.getRealname());

       this.userMapper.selectPage(page,queryWrapper);

       return new DataGridView(page.getTotal(),page.getRecords());
    }







}
